﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTC.Model.TestCore;
using System.Data.Common;
using IMPlant.Core.Data.Unity;
using System.Data;

namespace SMTC.Dao.Employee
{
    public class EmployeeProccessDao : BaseDao
    {
        #region SQL语句
        private const string SQL_INSERT_Employee = @"insert into SMT_UserInfo(EmpNbr,EmpName,EmpDep,Position,ExtNum,MTel,Email,Fax,Remark,UserName,UserPsw)
                                                   values(@EmpNbr,@EmpName,@EmpDep,@Position,@ExtNum,@MTel,@Email,@Fax,@Remark,@UserName,@UserPsw)";
        private const string SQL_UPDATE_Employee = @"update SMT_UserInfo set EmpNbr=@EmpNbr,EmpName=@EmpName,EmpDep=@EmpDep,
                                                    Position=@Position,ExtNum=@ExtNum,MTel=@MTel,Email=@Email,Fax=@Fax,Remark=@Remark,UserName=@UserName,UserPsw=@UserPsw where UserID=@UserID";
        private const string SQL_DELETE_Employee = @"delete from SMT_UserInfo  where UserID=@UserID ";
        private const string SQL_INSERT_List_Employee = @"insert into SMT_UserInfo(EmpNbr,EmpName,EmpDep,Position,ExtNum,MTel,Email,Fax,Remark)
                                                   values(@EmpNbr,@EmpName,@EmpDep,@Position,@ExtNum,@MTel,@Email,@Fax,@Remark)";

        #endregion
        #region 处理方法
        public bool InsertEmployee(EmpInfo employee)
        {
            DbParameter[] parameter = 
            {
                DBparameterBuild.Build("@EmpNbr",employee.EmpNbr)
                ,DBparameterBuild.Build("@EmpName",employee.EmpName)
                ,DBparameterBuild.Build("@EmpDep",employee.EmpDep)
                ,DBparameterBuild.Build("@Position",employee.Position)            
                ,DBparameterBuild.Build("@ExtNum",employee.ExtNum)
                ,DBparameterBuild.Build("@MTel",employee.MTel)
                ,DBparameterBuild.Build("@Email",employee.EMail)
                ,DBparameterBuild.Build("@Fax",employee.Fax)
                ,DBparameterBuild.Build("@Remark",employee.Remark)
                 ,DBparameterBuild.Build("@UserName",employee.UserName)
                ,DBparameterBuild.Build("@UserPsw",employee.UserPsw)
               
            };

            try
            {
                return DBTemplete.ExcuteNoQuery(CommandType.Text, SQL_INSERT_Employee, parameter) > 0;
            }
            catch
            {
                return false;
            }

        }
        public bool UpdateEmployee(EmpInfo employee)
        {
            DbParameter[] parameter = 
            {
                 DBparameterBuild.Build("@UserID",employee.UserID)
                 ,DBparameterBuild.Build("@EmpNbr",employee.EmpNbr)
                ,DBparameterBuild.Build("@EmpName",employee.EmpName)
                ,DBparameterBuild.Build("@EmpDep",employee.EmpDep)
                ,DBparameterBuild.Build("@Position",employee.Position)
                ,DBparameterBuild.Build("@ExtNum",employee.ExtNum)
                 ,DBparameterBuild.Build("@MTel",employee.MTel)
                ,DBparameterBuild.Build("@Email",employee.EMail)
                ,DBparameterBuild.Build("@Fax",employee.Fax)
                ,DBparameterBuild.Build("@Remark",employee.Remark)
                 ,DBparameterBuild.Build("@UserName",employee.UserName)
                ,DBparameterBuild.Build("@UserPsw",employee.UserPsw)
               
            };

            try
            {
                return DBTemplete.ExcuteNoQuery(CommandType.Text, SQL_UPDATE_Employee, parameter) > 0;
            }
            catch
            {
                return false;
            }
        }
        public bool DeleteEmployeebyID(string userid, ref DbTransaction dbt)
        {
            DbParameter[] parameter = 
            {
                DBparameterBuild.Build("@UserID",userid)
              
               
            };

            try
            {
                return DBTemplete.ExcuteNoQuery(CommandType.Text, SQL_DELETE_Employee, parameter,dbt) > 0;
            }
            catch
            {
                return false;
            }
        
        }
        public bool Insert_Llist_Employee(EmpInfo employee, ref DbTransaction dbt)
        {
             DbTransaction localDbt = null;
            if (dbt == null)
            {
                dbt = DBTemplete.CreateDbTransaction();
                localDbt = dbt;
            }
            else
            {
                localDbt = dbt;
            }
            DbParameter[] parameter = 
            {
                DBparameterBuild.Build("@EmpNbr",employee.EmpNbr)
                ,DBparameterBuild.Build("@EmpName",employee.EmpName)
                ,DBparameterBuild.Build("@EmpDep",employee.EmpDep)
                ,DBparameterBuild.Build("@Position",employee.Position)
                ,DBparameterBuild.Build("@ExtNum",employee.ExtNum)
                ,DBparameterBuild.Build("@MTel",employee.MTel)
                ,DBparameterBuild.Build("@Email",employee.EMail)
                ,DBparameterBuild.Build("@Fax",employee.Fax)
                ,DBparameterBuild.Build("@Remark",employee.Remark)
               
            };

            try
            {
                return DBTemplete.ExcuteNoQuery(CommandType.Text, SQL_INSERT_List_Employee, parameter, dbt) > 0;
            }
            catch
            {
                return false;
            }

        }
        #endregion
    }
}
